<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>退货</title>
<script type="text/javascript">
    function checkDecimal(obj) {
        var decimalReg=/^\d{0,9}\)?$/; //只能输入数字
        //var decimalReg = /^\d+(?=\.{0,1}\d+$|$)/; //可以输入数字或小数点
        if(obj.value!=""&&decimalReg.test(obj.value)){
        }else {
            if (obj.value != "") {
                //alert('非法值！请重新输入！');return ;
                obj.value = 0
            }
        }
    }
    function returnBack() {
        history.go(-1);
    }
    //输入判断
    function checkValue() {
        var obj_outstock_num =    document.getElementsByName('outstock_num[]');
        var obj_outstock_now = document.getElementsByName('goods_stock[]'); //现有库存
        var obj_orders = document.getElementsByName('outstock_order[]'); //出库订单
        var obj_savenum_id = document.getElementsByName('savenum_id[]'); //修改的id号
        var outstock_num="";
        var outstock_order = "";
        var savenum_id = "";
        var goods_sku = document.getElementById('goods_sku').value;
        var descr = document.getElementById('descr').value;
        for (var i=0;i<obj_outstock_num.length;i++)
        {
            var v = i+1; //判断第几个出库数量或类型没有填入
            if(!obj_outstock_num[i].value){
                alert("请填写第"+v+"的退货数量！");return ;
            }
            if(!obj_savenum_id[i].value){
                alert("第"+v+"的参数错误！");return ;
            }
            if(!obj_orders[i].value){
                alert("请填写第"+v+"的退货订单号！");return ;
            }
            outstock_num+=obj_outstock_num[i].value+','; //如果选中，将value添加到变量s中
            outstock_order+=obj_orders[i].value+','; //如果选中，将value添加到变量s中
            savenum_id+=obj_savenum_id[i].value+','; //如果选中，将value添加到变量s中
        }
        $.post(
                "/stocks/ajaxbutton",
                {"op":"returnGoods","outstock_num":outstock_num,"outstock_order":outstock_order,'descr':descr,'goods_sku':goods_sku,'savenum_id':savenum_id},
                function (data){
                    if(data.code){
                        alert(data.msg);
                        history.go(-1);
                        self.location=document.referrer;
                    }else {
                        alert(data.msg);return false;
                    }

                }, "json");
        return false;
    }
</script>
<body class="withvernav">
<div class="bodywrapper">
    {{include file='/public/leftmenu.tpl'}}
    <div class="centercontent">
        <div class="pageheader notab">
            <h1 class="pagetitle">退货</h1>
            <span class="pagedesc"></span>
        </div>
        <!--pageheader-->
        <div id="contentwrapper" class="contentwrapper">
            <div id="basicform" class="subcontent">
                <form class="stdform stdform2" method="post" id="search" action="/stocks/ajaxbutton">
                    <div class="tableoptions">
                        商品编号:
                        <input type="text" name="goods_sku[]" id="goods_sku" class="width400" value="{{$goods_sku}}"  readonly/><br/>
                        {{foreach from=$stocklist item=rs key=key}}
                        <input type="hidden" name="savenum_id[]" value="{{$rs.id}}">
                        商品型号:
                        <input type="text" name="goods_type[]" id="goods_type" class="width400" value="{{$rs.producttypename}}" readonly/><br/>
                        现有库存:
                        <input type="text" name="goods_stock[]" id="goods_stock" class="width400" value="{{$rs.savenum}}" readonly/><br/>
                        退货数量:
                        <input type="text" name="outstock_num[]" id="outstock_num" class="width400" value="" onblur="checkDecimal(this)" placeholder="请输入退货数量"/><br/>
                        退货订单:
                        <input type="text" name="outstock_order[]" id="outstock_order" class="width400" value="" placeholder="请输入退货订单"/><br/>
                        <br/><br/>
                        <hr style="color:#66c9f3;"/>
                        <br/>
                        {{/foreach}}
                        描述:
                        <textarea name="descr" id="descr"></textarea>
                        <br/>
                        <input type="hidden" name="op" value="returnGoods">
                        &nbsp;
                        <button type="button" class="btn btn-primary" onclick="checkValue()">确认保存</button>
                        <button type="button" class="btn btn-primary" onclick="returnBack()">返回</button>
                    </div>
            </div>
            </form>
        </div>
    </div>
</body>
</html>